package leetcode.L500;

import java.lang.reflect.Array;
import java.util.ArrayList;

public class EX407 {

    public static void main(String[] args) {
        String num = "1234567890";
        int k = 9;

        int[] stk = new int[10010];
        int tt = 0;
        stk[tt] = num.charAt(0)-48;
        for (int i = 1; i <num.length() ; i++) {
            int tp = num.charAt(i)-48;
            while(tt>-1&&tp<stk[tt]){
                if(k>0){
                    tt--;
                    k--;
                }
                else{
                    break;
                }
            }
            stk[++tt] = tp;
        }
        if(k>0){
            tt-=k;
        }
        String res = "";
        int f = 0;
        for (int i = 0; i <= tt ; i++) {
            if(stk[i]!=0||f == 1){
                res = res+String.valueOf(stk[i]);
                f=1;
            }
        }
        if(res.equals("")){
            res = "0";
        }
        System.out.println(res);
    }
}
